
"""
    pyprosim - a simple prolog compiler developed to PCS2056 course (Compilers) at Poli-USP\
    Copyright (C) 2008 Rodrigo Rodrigues da Silva

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
"""

import unittest

from pyprosim.token import token
from pyprosim.tokenizer import tokenizer
from pyprosim.maq_programa import maq_programa
from pyprosim.maq_dado import maq_dado
from pyprosim.maq_args import maq_args
from pyprosim.maq_lclausula import maq_lclausula
import logging

class testmaquinas(unittest.TestCase):
    
    tkzr = None
    
    def setUp(self):
        pass
        
    def test_maq_dado(self):
        self.tkzr = tokenizer(open('cases/testdado', 'r'))
        md = maq_dado(self.tkzr)
        md.analyze()
        self.tkzr.next_token()
        md = maq_dado(self.tkzr)
        try: md.analyze()
        except Exception:
            logging.debug("Detectou erro no dado! INF nao eh dado!")
            jogou=True
        if not jogou:
            self.fail() 
    def test_maq_args(self):
        pass
    
    def test_maq_lclausula(self):
        self.tkzr = tokenizer(open('cases/testlclausula', 'r'))
        mc = maq_lclausula(self.tkzr)
        mc.analyze()
    
    def test_maq_programa1(self):
        self.tkzr = tokenizer(open('cases/testprolog1', 'r'))
        mp = maq_programa(self.tkzr)
        mp.analyze()
        
    def test_maq_programa2(self):
        self.tkzr = tokenizer(open('cases/testprolog2', 'r'))
        mp = maq_programa(self.tkzr)
        mp.analyze()
    
    def TestSuite():
        return unittest.makeSuite(testmaquinas)
    
    if __name__ == '__main__':
        unittest.main()
 
        
  